package adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sxpjyy.monkey.mobilenurse.R;

import java.util.List;

import objects.LisJYJG;

/**
 * Created by Monkey on 2017/3/10.
 */

public class JYJGListAdapter extends BaseAdapter {

    private Context mContext;
    private List<LisJYJG> list;
    private LayoutInflater inflater;

    public JYJGListAdapter(Context context) {
        this.mContext = context;
        this.inflater = LayoutInflater.from(context);
    }

    public void setList(List<LisJYJG> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        if (list != null && list.size() > 0) {
            return list.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int i) {
        if (list != null && list.get(i) != null) {
            return list.get(i);
        }
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_jyjg, parent, false);
            holder.jg_name = (TextView) convertView.findViewById(R.id.jg_name);
            holder.jg_value = (TextView) convertView.findViewById(R.id.jg_value);
            holder.jg_flag = (TextView) convertView.findViewById(R.id.jg_flag);
            holder.jg_unit = (TextView) convertView.findViewById(R.id.jg_unit);
            holder.jg_reference = (TextView) convertView.findViewById(R.id.jg_reference);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (list != null && list.size() > 0) {
            if (list.get(position) != null) {
                LisJYJG lisJYJG = list.get(position);
                String XMMC = lisJYJG.getXMMC() != null ? lisJYJG.getXMMC() : "";
                holder.jg_name.setText(XMMC);
                String JG = lisJYJG.getJG() != null ? lisJYJG.getJG() : "";
                holder.jg_value.setText(JG);
                String YCXS = lisJYJG.getYCXS() != null ? lisJYJG.getYCXS() : "";
                holder.jg_flag.setText(YCXS);
                String DW = lisJYJG.getDW() != null ? lisJYJG.getDW() : "";
                holder.jg_unit.setText(DW);
                String CKZ = lisJYJG.getCKZ() != null ? lisJYJG.getCKZ() : "";
                holder.jg_reference.setText(CKZ);
            }
        }
        return convertView;
    }

    private class ViewHolder {
        private TextView jg_name;
        private TextView jg_value;
        private TextView jg_flag;
        private TextView jg_unit;
        private TextView jg_reference;
    }
}
